﻿using System;

namespace MadLibrary.Managing.Tasks
{
    /// <summary>Task.</summary>
    public class Task
    {
        /// <summary>Gets or sets the subject.</summary>
        /// <value>The subject.</value>
        public string Subject { get; set; }

        /// <summary>Gets or sets the description.</summary>
        /// <value>The description.</value>
        public string Description { get; set; }

        /// <summary>Gets or sets the status.</summary>
        /// <value>The status.</value>
        public TaskStatus Status { get; set; }

        /// <summary>Gets or sets the Date/Time of the start.</summary>
        /// <value>The start.</value>
        public DateTime Start { get; set; }

        /// <summary>Gets or sets the estimated end.</summary>
        /// <value>The estimated end.</value>
        public DateTime? EstimatedEnd { get; set; }

        /// <summary>Gets or sets the priority.</summary>
        /// <value>The priority.</value>
        public TaskPriority Priority { get; set; }

        /// <summary>
        /// Initializes a new instance of the <see cref="Task"/> class.
        /// </summary>
        public Task()
        {
            this.Subject = string.Empty;
            this.Description = string.Empty;
            this.Status = TaskStatus.Waiting;
            this.Start = DateTime.Now;
            this.Priority = TaskPriority.Low;
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="Task"/> class.
        /// </summary>
        /// <param name="Subject">The subject.</param>
        /// <param name="Description">The description.</param>
        public Task(string Subject, string Description)
        {
            this.Subject = Subject;
            this.Description = Description;
            this.Status = TaskStatus.Waiting;
            this.Start = DateTime.Now;
            this.Priority = TaskPriority.Low;
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="Task"/> class.
        /// </summary>
        /// <param name="Subject">The subject.</param>
        /// <param name="Description">The description.</param>
        /// <param name="Priority">The priority.</param>
        public Task(string Subject, string Description, TaskPriority Priority)
        {
            this.Subject = Subject;
            this.Description = Description;
            this.Status = TaskStatus.Waiting;
            this.Start = DateTime.Now;
            this.Priority = Priority;
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="Task"/> class.
        /// </summary>
        /// <param name="Subject">The subject.</param>
        /// <param name="Description">The description.</param>
        /// <param name="Status">The status.</param>
        public Task(string Subject, string Description, TaskStatus Status)
        {
            this.Subject = Subject;
            this.Description = Description;
            this.Status = Status;
            this.Start = DateTime.Now;
            this.Priority = TaskPriority.Low;
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="Task"/> class.
        /// </summary>
        /// <param name="Subject">The subject.</param>
        /// <param name="Description">The description.</param>
        /// <param name="Status">The status.</param>
        /// <param name="Priority">The priority.</param>
        public Task(string Subject, string Description, TaskStatus Status, TaskPriority Priority)
        {
            this.Subject = Subject;
            this.Description = Description;
            this.Status = Status;
            this.Start = DateTime.Now;
            this.Priority = Priority;
        }

        /// <summary>Initializes a new instance of the <see cref="Task"/> class.</summary>
        /// <param name="Subject">The subject.</param>
        /// <param name="Description">The description.</param>
        /// <param name="Status">The status.</param>
        /// <param name="Start">Start date and time.</param>
        /// <param name="EstimatedEnd">(optional) the estimated end.</param>
        public Task(string Subject, string Description, TaskStatus Status, DateTime Start, DateTime? EstimatedEnd = null)
        {
            this.Subject = Subject;
            this.Description = Description;
            this.Status = Status;
            this.Start = Start;
            this.Priority = TaskPriority.Low;
            this.EstimatedEnd = EstimatedEnd;
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="Task"/> class.
        /// </summary>
        /// <param name="Subject">The subject.</param>
        /// <param name="Description">The description.</param>
        /// <param name="Status">The status.</param>
        /// <param name="Priority">The priority.</param>
        /// <param name="Start">Start date and time.</param>
        /// <param name="EstimatedEnd">Estimated end time.</param>
        public Task(string Subject, string Description, TaskStatus Status, TaskPriority Priority, DateTime Start, DateTime? EstimatedEnd = null)
        {
            this.Subject = Subject;
            this.Description = Description;
            this.Status = Status;
            this.Start = Start;
            this.Priority = Priority;
            this.EstimatedEnd = EstimatedEnd;
        }

        /// <summary>
        /// ToString method
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            string status = "";
            string priority = "";
            switch (this.Status)
            {
                case TaskStatus.Done:
                    status = "Done";
                    break;
                case TaskStatus.Ending:
                    status = "Ending";
                    break;
                case TaskStatus.Undone:
                    status = "Undone";
                    break;
                case TaskStatus.Waiting:
                    status = "Waiting";
                    break;
                case TaskStatus.Working:
                    status = "Working";
                    break;
                default:
                    status = "Waiting";
                    break;
            }
            switch (this.Priority)
            {
                case TaskPriority.High:
                    priority = "High";
                    break;
                case TaskPriority.Low:
                    priority = "Low";
                    break;
                case TaskPriority.Medium:
                    priority = "Medium";
                    break;
                case TaskPriority.VeryHigh:
                    priority = "Very High";
                    break;
                case TaskPriority.VeryLow:
                    priority = "Very Low";
                    break;
            }
            return
                string.Format(
                    "Subject: {0}\r\nDescription: {1}\r\nStatus: {2}\r\nStart: {3}\r\nEstimatedEnd: {4}\r\nPriority: {5}\r\n",
                    Subject, Description, status, Start, EstimatedEnd, priority);
        }
    }
}